
Page({
  data: {
    latitude: 0, 
    longitude: 0,
    controls:[],
    markers: []
  },
  //首次加载时被调用
  onLoad: function () {
    var that= this;
   
    wx.getLocation({
      success: function(res) {
      var log= res.longitude
      var lat =res.latitude
      that.setData({
        longitude:log,
        latitude:lat
      })
      },
    })

    wx.getSystemInfo({
      success: function(res) {
        var windowWidth = res.windowWidth
        var windowHeight = res.windowHeight
        that.setData({
          controls: [{
            id: 0,
            iconPath: '/imgs/useCar.png',
            position: {
              width: 100,
              height: 100,
              left: windowWidth / 2 - 50,
              top: windowHeight - 120
            },
            clickable: true
          },
          {
            id: 1,
            iconPath: '/imgs/myCenter.png',
            position:{
              width: 25,
              height: 25,
              left: 10,
              top: 20
            },
            clickable: true
          },
          {
              id: 2,
              iconPath: '/imgs/position.png',
              position: {
                width: 25,
                height: 25,
                left:10,
                top: windowHeight-80
              },
              clickable: true
            },
            {
              id: 3,
              iconPath: '/imgs/help.png',
              position: {
                width: 25,
                height: 25,
                left: 10,
                top: windowHeight - 120
              },
              clickable: true
            },
            {
              id: 4,
              iconPath: '/imgs/fresh.png',
              position: {
                width: 20,
                height: 20,
                left: windowWidth-35,
                top: windowHeight - 80
              },
              clickable: true
            },
            {
              id: 5,
              iconPath: '/imgs/cur.png',
              position: {
                width: 20,
                height: 20,
                left: windowWidth / 2 -10,
                top: windowHeight / 2 -15
              },
              clickable: true
            }
          ]
        })
      },
    })
  },
  /**
   * 控件被点击
   */
  controltap:function(e){
    var that =this;
    var cid = e.controlId;
    console.log(cid);
    switch(cid){
      //用车
      case 0:{
        //根据用户状态，跳转到对应的页面
        var status = getApp().globalData.status;
        //如果是0，跳转到手机注册页面
        if (status == 0) {
          //跳转手机注册页面
          wx.navigateTo({
            url: '../register/register',
          })
        }
        break;
      }
      //个人中心
      case 1:{
        //根据用户状态，跳转到对应的页面
        var status=getApp().globalData.status;
        //如果是0，跳转到手机注册页面
        if(status==0){
          //跳转手机注册页面
          wx.navigateTo({
            url: '../register/register',
          })
        }else {
          //跳转个人中心页面
          wx.navigateTo({
            url: '../myCenter/myCenter',
          })
        }
        break;
      }
      //定位
      case 2:{
        this.mapCtx.moveToLocation()
        break;
      }
      //客服帮助
      case 3:{
        wx.navigateTo({
          url: '../user/user',
        })
          break;
      }
      //刷新
      case 4:{
        break;
      }
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady:function(){
    //创建map上下文
    this.mapCtx = wx.createMapContext("myMap")
  },
  /**
   * 移动后视野发生变化触发事件
   */
  regionchange: function (e) {
    var that = this
    //获取移动后的位置
    var etype = e.type
    if (etype == "end") {
      this.mapCtx.getCenterLocation({ 
        success: function (res) {
          var lat = res.latitude
          var log = res.longitude
        //  findBikes(log, lat, that)

        }
      })
    }
  }
  }
)
